package com.atguigu.mq.listener;

import com.rabbitmq.client.Channel;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Slf4j
public class MyMessageListener7lookDie {
    //监听死信队列
    @RabbitListener(queues = {"queue.test.sideduilie"})
    public void LookDieDuiLie(String dataString ,Message message, Channel channel) throws IOException {
        log.info(" ");
        log.info("消息是" + dataString);
        //单个处理。。。。。可靠性传递
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }


    //拒收
@RabbitListener(queues = {"queue.test.huodeduilie"})
    public void processMessageNormal(Message message, Channel channel) throws IOException {
        // 监听正常队列，但是拒绝消息
        log.info("★[normal]消息接收到，但我拒绝。");
        channel.basicReject(message.getMessageProperties().getDeliveryTag(), false);
    }
}
